var app = getApp();
import { config } from '../../../utils/config'
import util from '../../../utils/util'
import api from '../../../utils/api.js'


Page({
    /**
     * 页面的初始数据
     */
    data: {
        imgUrl: config.imgUrl,
        scrollId: "I0", //定位标签的id
        categoryIndex: 0,
        gzDialog: {
            show: false,
            showCancel: false,
            showConfirm: true,
            toggle: function () {
                this.show = !this.show;
                return this;
            }
        },
    },
    gzDialogToggle: function (e) {
        console.log("trig")
        this.setData({
            gzDialog: this.data.gzDialog.toggle()
        });
    },
    onLoad: function (options) {
        // 判断用户是否是会员身份
        let is_member = wx.getStorageSync('is_member');
        this.setData({
            is_member
        })
        //获取积分商城首页内容
        this.integralHome();

        // 获取剩余积分 
        this.accountPoints();

        // 获取消息列表接口
        this.getInteNotice();

        // 十分钟更新数据
        setInterval(() => {
            this.getInteNotice();
        }, 600000);
    },
    getInteNotice() {
        let that = this;
        util.getInfo(api.getInteNotice, 'GET', {}, false).then(res => {
            this.setData({
                noticeList: res
            })
        })
    },
    /*首页内容获取接口*/
    integralHome() {
        let that = this;
        util.getInfo(api.integralHome, 'GET', {}).then(res => {
            this.setData(res)
            this.setData({
                freeList: res.free[this.data.categoryIndex].product
            })
        })
    },
    /*切换分类*/
    changeCagegory(e) {
        let id = e.currentTarget.dataset.id;
        let index = e.currentTarget.dataset.index;
        this.setData({
            categoryIndex: index
        })
        //获取分类列表
        let free = this.data.free;
        let freeList = free[index].product;
        this.setData({
            freeList
        })

    },
    accountPoints() {
        util.getInfo(api.accountCoins, 'GET', {}).then(res => {
            this.setData({
                points: res.points
            })
        })
    },
    /*跳转到详情*/
    toDetail(e) {
        let id = e.currentTarget.dataset.id;
        let type = e.currentTarget.dataset.type;
        wx.navigateTo({
            url: `/pages/pointsMall/details/details?id=${id}&type=${type}`
        })
    },
    //积分
    toPoints() {
        wx.navigateTo({
            url: '/pages/getJiFen/getJiFen'
        })
    },
    toAngle() {
        wx.navigateTo({
            url: '/pages/pointsMall/angle/angle'
        })
    },
    toChange() {
        wx.navigateTo({
            url: '/pages/pointsMall/change/change'
        })
    },
})